package com.cloudlead.dictionaryAction.service.impl;

import com.cloudlead.common.lang.persistence.*;
import com.cloudlead.commonData.service.WechatlogService;
import com.cloudlead.commonData.vo.Wechatlog;
import com.cloudlead.dictionaryAction.service.WechatlogEditSer;
import com.cloudlead.dictionaryService.vo.WechatlogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/25.
 */
@Service
public class WechatlogSerImpl implements WechatlogEditSer {

    @Autowired
    WechatlogService wechatlogService;

    @Override
    public Page<Wechatlog> WechatlogList(WechatlogVo WechatlogVo, int rows, int page) {
        PageRequest pr = new PageRequest();
        List<Term> tr = new ArrayList<Term>();
        WechatlogVo vo=WechatlogVo==null?new WechatlogVo():WechatlogVo;
       // tr.add(new Term("flag","0"));
        if(vo.getDriverName() != null && !vo.getDriverName().equals("")){
            tr.add(new Term("driverName", Operator.LK, vo.getDriverName()+ "%"));

        }
        if(vo.getContainerNo() != null && !vo.getContainerNo().equals("")){
            tr.add(new Term("containerNo",vo.getContainerNo()));
        }
        if(vo.getTel() != null && !vo.getTel().equals("")){
            tr.add(new Term("tel",vo.getTel()));
        }
        if(vo.getNowTime() != null && !vo.getNowTime().equals("")){
            tr.add(new Term("nowTime", Operator.LK, vo.getNowTime()+ "%"));
        }
        Sort sort = new Sort();
        if(vo!=null) {
            if (!"".equals(vo.getSort()) && vo.getSort() != null && !"".equals(vo.getOrder()) && vo.getOrder() != null) {
                sort.add(new Sort.Order(vo.getOrder().equals("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, vo.getSort()));
            }
        }
        pr.setPage(page);
        pr.setSize(rows);
        pr.setSort(sort);
        if(tr.size()>0)
        {Filter filter=new Filter(new Criteria(tr));
        pr.setFilter(filter);}
        return wechatlogService.findAll(pr);
    }
}
